import http from './../../../base/api/public'
import querystring from 'querystring'

let sysConfig = require('@/../config/sysConfig')
let apiUrl = sysConfig.xcApiUrlPre;

//查询课程列表
//我的课程列表
export const findCourseList = (page, size, params) => {
//使用工具类将json对象转成key/value
  let queries = querystring.stringify(params);
  return http.requestQuickGet(apiUrl + "/course/coursebase/list/" + page + "/" + size + "?" + queries)
};
export const getCoursebaseById = (courseid) => {
  return http.requestQuickGet(apiUrl + "/course/coursebase/fetch/" + courseid)
};
/*修改课程基本数据*/
export const updateCoursebase = courseForm => {
  return http.requestPost(apiUrl + '/course/coursebase/update', courseForm);
};

/*查询课程营销*/
export const getCourseMarketById = courseid => {
  return http.requestGet(apiUrl + '/course/coursemarket/fetch/' + courseid);
};
/*修改课程营销数据*/
export const updateCourseMarket = (courseid, courseMarketForm) => {
  return http.requestPost(apiUrl + '/course/coursemarket/update/' + courseid, courseMarketForm);
};


//查询课程分类
export const category_findlist = () => {
  return http.requestQuickGet(apiUrl + '/category/list')
};
/*添加课程基础信息*/
export const addCourseBase = params => {
  return http.requestPost(apiUrl + '/course/coursebase/add', params)
};

/*查询课程计划*/
export const findTeachplanList = courseid => {
  return http.requestQuickGet(apiUrl + '/course/teachplan/list/' + courseid)
};
/*添加课程计划*/
export const addTeachplan = teachplan => {
  return http.requestPost(apiUrl + '/course/teachplan/add', teachplan)
};
/*删除课程计划*/
export const deleteTeachplan = id => {
  return http.requestDelete(apiUrl + '/course/teachplan/delete/' + id)
};
/*修改课程计划*/
export const updateTeachplan = teachplan => {
  return http.requestPost(apiUrl + '/course/teachplan/update', teachplan)
};
/*回显课程计划*/
export const fetchTeachplan = id => {
  return http.requestGet(apiUrl + '/course/teachplan/fetch/' + id)
};


//保存课程图片地址到课程数据 库
export const addCoursePic = (courseId, pic) => {
  return http.requestPost(apiUrl + '/course/coursepic/add?courseId=' + courseId + "&pic=" + pic)
};
//查询课程图片
export const findCoursePicList = courseId => {
  return http.requestQuickGet(apiUrl + '/course/coursepic/list/' + courseId)
};

//删除课程图片
export const deleteCoursePic = courseId => {
  return http.requestDelete(apiUrl + '/course/coursepic/delete?courseId=' + courseId)
};


/*新增课程页面*/
export const addCoursePage = (courseId,templateId) => {
  return http.requestGet(apiUrl + '/course/addCoursePage/' + courseId + '/' + templateId);
};

/*预览课程*/
export const preview = pageid => {
  return http.requestGet(apiUrl + '/course/preview/' + pageid);
};
/*发布课程*/
export const publish = (id, templateFileId) => {
  return http.requestGet(apiUrl + '/course/publish/' + id + "/" + templateFileId);
};
/*静态化*/
export const staticHtml = (pageId) => {
  return http.requestGet(apiUrl + '/course/staticHtml/' + pageId);
};
/*真发布课程*/
export const publish_real = (pageId, courseId) => {
  return http.requestGet(apiUrl + '/course/publish_real/' + pageId + '/' + courseId);
};
//查询课程信息
export const findCourseView = courseId => {
  return http.requestQuickGet(apiUrl + '/course/coursebase/fetch/' + courseId)
};
//查询页面信息
export const getCmsPage = pageId => {
  return http.requestQuickGet(apiUrl + '/course/fetchCmsPage/' + pageId)
};
/*保存媒资信息*/
export const savemedia = teachplanMedia => {
  return http.requestPost(apiUrl + '/course/savemedia', teachplanMedia);
};


/*额外*/
/*模板列表*/
export const template_list = (page, size, params) => {
  //params为json格式
  //使用querystring将json对象转成key/value串
  let querys = querystring.stringify(params)
  return http.requestQuickGet(apiUrl + '/cms/template/list/' + page + '/' + size + '/?' + querys)
};
